home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / plot / mesh.m < prev    next >
Text File  |  1997-07-10  |  3KB  |  115 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## usage: mesh (x, y, z)
  21. ##
  22. ## Surface plot.  If x, y, and z are matrices with the same dimensions,
  23. ## then corresponding elements represent vertices of the plot.  If x and
  24. ## y are vectors, then a typical vertex is (x(j), y(i), z(i,j)).  Thus,
  25. ## columns of z correspond to different x values and rows of z correspond
  26. ## to different y values.
  27. ##
  28. ## See also: plot, semilogx, semilogy, loglog, polar, meshgrid, meshdom,
  29. ##           contour, bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title
  30.  
  31. ## Author: jwe
  32.  
  33. function mesh (x, y, z)
  34.  
  35.   ## XXX FIXME XXX -- these plot states should really just be set
  36.   ## temporarily, probably inside an unwind_protect block, but there is
  37.   ## no way to determine their current values.
  38.  
  39.   if (nargin == 1)
  40.     z = x;
  41.     if (is_matrix (z))
  42.       gset hidden3d;
  43.       gset data style lines;
  44.       gset surface;
  45.       gset nocontour;
  46.       gset noparametric;
  47.       gset view 60, 30, 1, 1
  48.       gsplot (z');
  49.     else
  50.       error ("mesh: argument must be a matrix");
  51.     endif
  52.   elseif (nargin == 3)
  53.     if (is_vector (x) && is_vector (y) && is_matrix (z))
  54.       xlen = length (x);
  55.       ylen = length (y);
  56.       if (xlen == columns (z) && ylen == rows (z))
  57.         if (rows (y) == 1)
  58.           y = y';
  59.         endif
  60.         len = 3 * xlen;
  61.         zz = zeros (ylen, len);
  62.         k = 1;
  63.         for i = 1:3:len
  64.           zz(:,i)   = x(k) * ones (ylen, 1);
  65.           zz(:,i+1) = y;
  66.           zz(:,i+2) = z(:,k);
  67.           k++;
  68.         endfor
  69.     gset hidden3d;
  70.     gset data style lines;
  71.         gset surface;
  72.         gset nocontour;
  73.     gset parametric;
  74.         gset view 60, 30, 1, 1
  75.     gsplot (zz);
  76.     gset noparametric;
  77.       else
  78.         msg = "mesh: rows (z) must be the same as length (x) and";
  79.         msg = sprintf ("%s\ncolumns (z) must be the same as length (y)", msg);
  80.         error (msg);
  81.       endif
  82.     elseif (is_matrix (x) && is_matrix (y) && is_matrix (z))
  83.       xlen = columns (z);
  84.       ylen = rows (z);
  85.       if (xlen == columns (x) && xlen == columns (y) &&
  86.     ylen == rows (x) && ylen == rows(y))
  87.         len = 3 * xlen;
  88.         zz = zeros (ylen, len);
  89.         k = 1;
  90.         for i = 1:3:len
  91.           zz(:,i)   = x(:,k);
  92.           zz(:,i+1) = y(:,k);
  93.           zz(:,i+2) = z(:,k);
  94.           k++;
  95.         endfor
  96.     gset hidden3d;
  97.     gset data style lines;
  98.         gset surface;
  99.         gset nocontour;
  100.     gset parametric;
  101.         gset view 60, 30, 1, 1
  102.     gsplot (zz);
  103.     gset noparametric;
  104.       else
  105.         error ("mesh: x, y, and z must have same dimensions");
  106.       endif
  107.     else
  108.       error ("mesh: x and y must be vectors and z must be a matrix");
  109.     endif
  110.   else
  111.     usage ("mesh (z)");
  112.   endif
  113.  
  114. endfunction
  115.